package com.mjk.common.core.jdbc.ibatis.interceptor;

import com.mjk.common.tools.logger.BizLogger;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;

import java.util.Properties;

//@Intercepts({
//	@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}),
//	@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
//	@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class,CacheKey.class,BoundSql.class})
//})
public class ExcuteErrorSqlInterceptor implements Interceptor{

	@Override
	public Object intercept(Invocation invocation) throws Throwable {
		try{
			return invocation.proceed();
		}catch(Exception e){
			Object[] objs = invocation.getArgs();
			BizLogger.error(objs[1]);
			throw e;
		}
	}

	@Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {
        //do noting
    }

}
